package com.contract.commonlib.webview;

import android.view.View;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.tencent.smtt.sdk.WebChromeClient;
import com.tencent.smtt.sdk.WebView;

/**
 * Created by Ace on 2018/5/11.
 */

public class MyWebChromeClient extends WebChromeClient {

    private ProgressBar progressBar;

    private TextView titleView;


    @Override
    public void onProgressChanged(WebView view, int newProgress) {
        super.onProgressChanged(view, newProgress);
        if (progressBar != null) {
            progressBar.setProgress(newProgress);
            if (newProgress < 100) {
                progressBar.setVisibility(View.VISIBLE);
            } else {
                progressBar.setVisibility(View.GONE);
            }
        }
    }

    @Override
    public void onReceivedTitle(WebView view, String title) {
        super.onReceivedTitle(view, title);
        if (titleView != null) {
            titleView.setText(title);
        }
    }

    public MyWebChromeClient setProgressBar(ProgressBar progressBar) {
        this.progressBar = progressBar;
        return this;
    }

    public void setTitleView(TextView titleView) {
        this.titleView = titleView;
    }
}
